home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / hplip / plugins / powersettingsdialog.py < prev   
Text File  |  2008-10-13  |  6KB  |  157 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. from base.g import *
  23. import powersettings
  24. import powersettings2
  25. from base import pml
  26.  
  27. from qt import *
  28. from powersettingsdialog_base import PowerSettingsDialog_base
  29.  
  30.  
  31. class PowerSettingsDialog(PowerSettingsDialog_base): # Dyn Ctr (DJ4xx)
  32.  
  33.     def __init__(self,value,parent = None,name = None,modal = 0,fl = 0):
  34.         PowerSettingsDialog_base.__init__(self,parent,name,modal,fl)
  35.         self.setting = 0 # 0=never off, 1=timed off
  36.  
  37.         log.debug("Initializing plugin dialog with power setting: %s" % value)
  38.  
  39.         self.power_setting_table = {0 : (self.__tr("15 minutes"), '015'),
  40.                                      1 : (self.__tr("30 minutes"), '030'),
  41.                                      2 : (self.__tr("45 minutes"), '045'),
  42.                                      3 : (self.__tr("1 hour"), '060'),
  43.                                      4 : (self.__tr("2 hours"), '120'),
  44.                                      5 : (self.__tr("3 hours"), '180'),
  45.                                     }
  46.  
  47.         for x in self.power_setting_table:
  48.             self.power_setting_combo.insertItem(self.power_setting_table[x][0], x)
  49.  
  50.         if value == '999':
  51.             self.power_setting.setButton(0)
  52.             #self.setting = 0
  53.         else:
  54.             self.power_setting.setButton(1)
  55.             self.setting = 1
  56.  
  57.             for x in self.power_setting_table:
  58.                 if self.power_setting_table[x][1] == value:
  59.                     self.power_setting_combo.setCurrentItem(x)
  60.  
  61.  
  62.     def power_setting_clicked(self,a0):
  63.         self.setting = a0
  64.         log.debug("Setting (0=Always on/1=Timed off): %s" % a0)
  65.  
  66.     def getValue(self):
  67.         return self.power_setting_table[self.power_setting_combo.currentItem()][1]
  68.  
  69.     def __tr(self,s,c = None):
  70.         return qApp.translate("PowerSettingsDialog",s,c)
  71.  
  72.  
  73. class PowerSettingsDialog2(PowerSettingsDialog_base): # PML (OJ H4xx)
  74.  
  75.     def __init__(self,value,parent = None,name = None,modal = 0,fl = 0):
  76.         PowerSettingsDialog_base.__init__(self,parent,name,modal,fl)
  77.         self.setting = 0 # 0=never off, 1=timed off
  78.  
  79.         log.debug("Initializing plugin dialog with power setting: %s" % value)
  80.  
  81.         self.power_setting_table = {0 : (self.__tr("15 minutes"), pml.OID_POWER_SETTINGS_15MIN),
  82.                                      1 : (self.__tr("30 minutes"), pml.OID_POWER_SETTINGS_30MIN),
  83.                                      2 : (self.__tr("45 minutes"), pml.OID_POWER_SETTINGS_45MIN),
  84.                                      3 : (self.__tr("1 hour"), pml.OID_POWER_SETTINGS_1HR),
  85.                                      4 : (self.__tr("2 hours"), pml.OID_POWER_SETTINGS_2HR),
  86.                                      5 : (self.__tr("3 hours"), pml.OID_POWER_SETTINGS_3HR),
  87.                                     }
  88.  
  89.         for x in self.power_setting_table:
  90.             self.power_setting_combo.insertItem(self.power_setting_table[x][0], x)
  91.  
  92.         if value == pml.OID_POWER_SETTINGS_NEVER:
  93.             self.power_setting.setButton(0)
  94.         else:
  95.             self.power_setting.setButton(1)
  96.             self.setting = 1
  97.  
  98.             for x in self.power_setting_table:
  99.                 if self.power_setting_table[x][1] == value:
  100.                     self.power_setting_combo.setCurrentItem(x)
  101.  
  102.  
  103.     def power_setting_clicked(self,a0):
  104.         self.setting = a0
  105.         log.debug("Setting (0=Always on/1=Timed off): %s" % a0)
  106.  
  107.     def getValue(self):
  108.         return self.power_setting_table[self.power_setting_combo.currentItem()][1]
  109.  
  110.     def __tr(self,s,c = None):
  111.         return qApp.translate("PowerSettingsDialog2",s,c)
  112.  
  113.  
  114. def settingsUIDynCtr(d, parent):
  115.     value = powersettings.getPowerSettings(d)
  116.     log.debug("Battery power settings: %s" % value)
  117.  
  118.     dlg = PowerSettingsDialog(value, parent)
  119.  
  120.     if dlg.exec_loop() == QDialog.Accepted:
  121.         value = dlg.getValue()
  122.         log.debug("Power setting set to %s in dialog" % value)
  123.  
  124.         if dlg.setting == 0:
  125.             powersettings.setPowerSettings(d, '999')
  126.         else:
  127.             powersettings.setPowerSettings(d, value)
  128.  
  129.  
  130. def settingsUIPML(d, parent):
  131.     value = powersettings2.getPowerSettings(d)
  132.     log.debug("Battery power settings: %s" % value)
  133.  
  134.     dlg = PowerSettingsDialog2(value, parent)
  135.  
  136.     if dlg.exec_loop() == QDialog.Accepted:
  137.         value = dlg.getValue()
  138.         log.debug("Power setting set to %s in dialog" % value)
  139.  
  140.         if dlg.setting == 0:
  141.             powersettings2.setPowerSettings(d, pml.OID_POWER_SETTINGS_NEVER)
  142.         else:
  143.             powersettings2.setPowerSettings(d, value)
  144.  
  145.  
  146. def settingsUI(d, parent=None):
  147.     log.debug("settingsUI(%s)" % __file__)
  148.  
  149.     battery_check = d.mq['power-settings']
  150.  
  151.     if battery_check == POWER_SETTINGS_EPML:
  152.         return settingsUIDynCtr(d, parent)
  153.  
  154.     elif battery_check == POWER_SETTINGS_PML:
  155.         return settingsUIPML(d, parent)
  156.  
  157.